package hello.app.model;

import hello.app.util.Util;
import android.content.Context;

/**
 * モデル管理クラス
 *
 */
public class ModelManager {

	private static ModelManager instance = null;
	private static boolean created = false;
	/* 自前のデータベース */
	private HelloContactModel mHelloContactModel;			//コンタクト
	private CommentModel mCommentModel;			//コメント
	/* Preference */
	private HelloSetting mHelloSetting;			//誰着設定
	/* Sytemのデータベース */
	private MyContactModel myContactModel;		//自分の連絡先にあるコンタクト
	private CallHistoryModel mCallHistoryModel;	//着信履歴
	/* 誰着サーバーへのインターフェース */
	private HelloApi mHelloApi;

	private ModelManager(Context context){
		mHelloContactModel = new HelloContactModel(context);
		mCommentModel = new CommentModel(context);
		myContactModel = new MyContactModel(context.getApplicationContext().getContentResolver());
		mHelloSetting = new HelloSetting(context);
		mCallHistoryModel = new CallHistoryModel(context.getApplicationContext().getContentResolver());
		mHelloApi = HelloApi.getInstance(hello.app.Application.SERVER_URL);
		mHelloApi.setSecurityDeviceId(Util.getDeviceId(context));
	}

	public static ModelManager getInstatce() throws Exception{
		if(created == false){
			throw new Exception("instance is not created");
		}
		return instance;
	}

	public static ModelManager getInstatce(Context context){
		if(instance == null){
			instance = new ModelManager(context);
			created = true;
		}
		return instance;
	}

	public HelloContactModel getHelloContactModel(){
		return mHelloContactModel;
	}

	public CommentModel getCommentModel(){
		return mCommentModel;
	}

	public MyContactModel getMyContactModel(){
		return myContactModel;
	}

	public HelloSetting getHelloSetting(){
		return mHelloSetting;
	}

	public CallHistoryModel getCallHistoryModel() {
		return mCallHistoryModel;
	}

	public HelloApi getHelloApi() {
		return mHelloApi;
	}

}
